<template>
  <div class="contioner">
    <div ref="myChart" :style="{ width: '100%', height: '100%' }"></div>
  </div>
</template>
      
  <script lang="ts" setup>
import * as echarts from 'echarts'
import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
//引入封装post
import { post } from '@/api/http'
import dayjs from 'dayjs'
//getlist初始化接口参数
let query: any = reactive({
  beginDate: dayjs().format('YYYY'), //当天日期
    planOrderCode: localStorage.getItem('firmId') || '',
})

const option = ref({
  title: {
    text: '织厂月产量',
    /*textVerticalAlign:'center'*/
    top: '0',
    left: '0',
  },
  tooltip: {
    trigger: 'axis',
  },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '0%',
    containLabel: true,
  },
  xAxis: {
    type: 'category',
    data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  },
  yAxis: {
    type: 'value',
    splitNumber: 2,
    // axisLabel: {
    //     formatter: '{value} %'
    // }
  },
  series: [
    {
      name: '月目标',
      type: 'bar',
      // stack: 'Total',
      data: [120, 132, 101, 134, 90, 230, 120],
      barWidth: 50,
      label: { show: true, position: 'top', distance: 10 },
    },
    {
      name: '累计总产量(吨)',
      type: 'bar',
      // stack: 'Total',
      data: [220, 182, 191, 234, 290, 330, 310],
      barWidth: 50,
      label: { show: true, position: 'top', distance: 10 },
    },
    {
      name: '日产目标值(吨/天)',
      type: 'line',
      // stack: 'Total',
      data: [150, 232, 201, 154, 190, 330, 410],
      label: { show: true, position: 'top', distance: 10 },
    },
    {
      name: '日均产量(吨/天)',
      type: 'line',
      // stack: 'Total',
      data: [150, 232, 201, 154, 190, 330, 410],
      label: { show: true, position: 'top', distance: 10 },
    },
  ],
})

//初始化
onMounted(async () => {
  selectJt()
    // const state = states()
  // state.setOption(option.value)
})
const myChart: any = ref()
const states = () => {
  return echarts.init(myChart.value)
}
function selectJt() {
  post({
    url: 'qms/report/companyOutputReportByDay',
    data: {
      firmId: query.planOrderCode,
      date: '',
    },
  }).then((res: any) => {
    if (res.code == 200) {
      let x = res.data.map((o: any) => {
        return o['dateByDay']
      })
      let goalByDay = res.data.map((o: any) => {
        return o['goalByDay']
      })
      let outputByDay = res.data.map((o: any) => {
        return o['outputByDay']
      })
      option.value.xAxis.data = x
      option.value.series[0].data = outputByDay
      option.value.series[1].data = goalByDay
      const state = states()
      state.setOption(option.value)
    } else {
      Message.error(res.message)
    }
  })
}
</script>
  <script lang="ts">
export default defineComponent({
  name: 'MonthlyOutputOfTheWeavingPlant',
})
</script>
  <style scoped>
.contioner {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 10px;
}

:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
      